var express = require('express');
var router = express.Router();

const {
    addSellers,
    getAllSellers,
    getSellers,
    getSellersById,
    changeSellersById,
    delSellersById,
    loginSellers,
    getSellersOrderById,
    getSellersUserById,
    getSellersByIdForClaims
} = require("../service/sellersService")

/* GET home page. */

// 销售员登录
router.post('/loginSellers', async function (req, res, next) {
    const data = await loginSellers(req.body);
    res.send(data);
});

// 添加销售员
router.post('/addSellers', async function (req, res, next) {
    const data = await addSellers(req.body)
    console.log(req.body);
    res.send(data)
});

// 获取所有销售人员
router.get('/getAllSellers', async function (req, res, next) {
    const data = await getAllSellers({
        delete: false
    })
    res.send(data)
});


// 获取销售人员
router.get('/getSellers', async function (req, res, next) {
    const data = await getSellers(req.query);
    console.log(req.query);
    res.send(data)
});


// 根据_id获取销售人员
router.get('/getSellersById', async function (req, res, next) {
    const data = await getSellersById(req.query);
    console.log(req.query);
    res.send(data)
});


// 根据_id修改销售人员
router.post('/changeSellersById', async function (req, res, next) {
    const data = await changeSellersById(req.body);
    console.log(req.body);
    res.send(data)
});


//根据_id删除销售人员
router.post('/delSellersById', async function (req, res, next) {
    const data = await delSellersById(req.body);
    res.send(data)
});


// 根据_id获取我的全部订单
router.get('/getSellersOrderById', async function (req, res, next) {
    const data = await getSellersOrderById(req.query);
    console.log(req.query);
    console.log(data);
    res.send(data)
});


// 根据_id获取我的客户
router.get('/getSellersUserById', async function (req, res, next) {
    const data = await getSellersUserById(req.query);
    res.send(data)
});

// 获取我的所有理赔
router.get('/getSellersByIdForClaims', async function (req, res, next) {
    const data = await getSellersByIdForClaims(req.query);
    res.send(data)
});
module.exports = router;